﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Drawing;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Content;

/// <summary>
/// Summary description for EtiqaPAInsurancePDFOutput
/// </summary>
/// 
namespace CE.PersonalAccident
{
    public class EtiqaPAInsurancePDFOutput
    {
        private string _proposalId;
        public string ProposalId
        {
            get { return _proposalId; }
            set { _proposalId = value; }
        }

        private string _schedulewritingpagetitle;// "Etiqa - Schedule Writing";
        public string ScheduleWritingPageTitle
        {
            get { return _schedulewritingpagetitle; }
            set { _schedulewritingpagetitle = value; }
        }

        private string _certificatepagetitle;// "Etiqa - Certificate Of Insurance";
        public string CertificatePageTitle
        {
            get { return _certificatepagetitle; }
            set { _certificatepagetitle = value; }
        }

        private string _taxinvoicepagetitle;// "Etiqa - Tax";
        public string TaxInvoicePageTitle
        {
            get { return _taxinvoicepagetitle; }
            set { _taxinvoicepagetitle = value; }
        }

        private bool _ispromo;
        public bool isPromo
        {
            get { return _ispromo; }
            set { _ispromo = value; }
        }

        private string _newpremium;
        public string NewPremium
        {
            get { return _newpremium; }
            set { _newpremium = value; }
        }

        #region Customer Profile
        string _customerName;
        public string CustomerName
        {
            get { return _customerName; }
            set { _customerName = value; }
        }

        string _customerAddress1;
        public string CustomerAddress1
        {
            get { return _customerAddress1; }
            set { _customerAddress1 = value; }
        }

        string _customerAddress2;
        public string CustomerAddress2
        {
            get { return _customerAddress2; }
            set { _customerAddress2 = value; }
        }

        #endregion

        #region Schedule Variables
        string _agency;
        public string Agency
        {
            get { return _agency; }
            set { _agency = value; }
        }

        string _classOfPolicy;
        public string ClassOfPolicy
        {
            get { return _classOfPolicy; }
            set { _classOfPolicy = value; }
        }

        string _policyNumber;
        public string PolicyNumber
        {
            get { return _policyNumber; }
            set { _policyNumber = value; }
        }

        string _account;
        public string Account
        {
            get { return _account; }
            set { _account = value; }
        }

        string _issuedOn;
        public string IssuedOn
        {
            get { return _issuedOn; }
            set { _issuedOn = value; }
        }

        string _replacePolicyNumber;
        public string ReplacePolicyNumber
        {
            get { return _replacePolicyNumber; }
            set { _replacePolicyNumber = value; }
        }

        string _client;// "";
        public string Client
        {
            get { return _client; }
            set { _client = value; }
        }

        string _acceptanceDate;
        public string AcceptanceDate
        {
            get { return _acceptanceDate; }
            set { _acceptanceDate = value; }
        }

        string _startPeriod;
        public string PeriodInsuranceStart
        {
            get { return _startPeriod; }
            set { _startPeriod = value; }
        }

        string _endPeriod;
        public string PeriodInsuranceEnd
        {
            get { return _endPeriod; }
            set { _endPeriod = value; }
        }

        string _totalDueInvoice;
        public string TotalDueInvoice
        {
            get { return _totalDueInvoice; }
            set { _totalDueInvoice = value; }
        }

        string _occupation;
        public string Occupation
        {
            get { return _occupation; }
            set { _occupation = value; }
        }

        string _nric;
        public string NRICNo
        {
            get { return _nric; }
            set { _nric = value; }
        }

        string _dob;
        public string DOB
        {
            get { return _dob; }
            set { _dob = value; }
        }

        string _planname;
        public string PlanName
        {
            get { return _planname; }
            set { _planname = value; }
        }

        string _accidentalDeath;
        public string AccidentalDeath
        {
            get { return _accidentalDeath; }
            set { _accidentalDeath = value; }
        }

        string _permanentDisability;
        public string PermanentDisability
        {
            get { return _permanentDisability; }
            set { _permanentDisability = value; }
        }

        string _totalParalysis;
        public string TotalParalysis
        {
            get { return _totalParalysis; }
            set { _totalParalysis = value; }
        }

        string _totalLossOfSight;
        public string TotalLossOfSight
        {
            get { return _totalLossOfSight; }
            set { _totalLossOfSight = value; }
        }

        string _totalLossOfSpeech;
        public string TotalLossOfSpeech
        {
            get { return _totalLossOfSpeech; }
            set { _totalLossOfSpeech = value; }
        }

        string _totalLossOfHearingBoth;
        public string TotalLossOfHearingBoth
        {
            get { return _totalLossOfHearingBoth; }
            set { _totalLossOfHearingBoth = value; }
        }

        //Classic Plan = default values
        string _totalLossOfOneLimb = "50,000";
        public string TotalLossOfOneLimb
        {
            get { return _totalLossOfOneLimb; }
            set { _totalLossOfOneLimb = value; }
        }

        string _totalLossOfHearingOne = "20,000";
        public string TotalLossOfHearingOne
        {
            get { return _totalLossOfHearingOne; }
            set { _totalLossOfHearingOne = value; }
        }

        string _totalLossElbow = "15,000";
        public string TotalLossElbow
        {
            get { return _totalLossElbow; }
            set { _totalLossElbow = value; }
        }

        string _totalLossOneThumb = "15,000";
        public string TotalLossOneThumb
        {
            get { return _totalLossOneThumb; }
            set { _totalLossOneThumb = value; }
        }

        string _totalLossOneForefinger = "10,000";
        public string TotalLossOneForefinger
        {
            get { return _totalLossOneForefinger; }
            set { _totalLossOneForefinger = value; }
        }

        string _totalLossAnyFinger = "5,000";
        public string TotalLossAnyFinger
        {
            get { return _totalLossAnyFinger; }
            set { _totalLossAnyFinger = value; }
        }

        string _totalLossAnyToe = "2,000";
        public string TotalLossAnyToe
        {
            get { return _totalLossAnyToe; }
            set { _totalLossAnyToe = value; }
        }

        string _compassionateCash = "1,000";
        public string CompassionateCash
        {
            get { return _compassionateCash; }
            set { _compassionateCash = value; }
        }

        string _medExpPerAccident = "1,000";
        public string MedExpPerAccident
        {
            get { return _medExpPerAccident; }
            set { _medExpPerAccident = value; }
        }

        string _hospitalConfinement;
        public string HospitalConfinement
        {
            get { return _hospitalConfinement; }
            set { _hospitalConfinement = value; }
        }

        string _outpatientCash = "50";
        public string OutpatientCash
        {
            get { return _outpatientCash; }
            set { _outpatientCash = value; }
        }

        string _outpatientMedExp = "100";
        public string OutpatientMedExp
        {
            get { return _outpatientMedExp; }
            set { _outpatientMedExp = value; }
        }

        string _chineseMedExp = "100";
        public string ChineseMedExp
        {
            get { return _chineseMedExp; }
            set { _chineseMedExp = value; }
        }

        string _snatchTheft = "100";
        public string SnatchTheft
        {
            get { return _snatchTheft; }
            set { _snatchTheft = value; }
        }

        string _dentalTreatment = "500";
        public string DentalTreatment
        {
            get { return _dentalTreatment; }
            set { _dentalTreatment = value; }
        }

        string _kidnapBenefit = "1,000";
        public string KidnapBenefit
        {
            get { return _kidnapBenefit; }
            set { _kidnapBenefit = value; }
        }

        string _ambulanceFee = "100";
        public string AmbulanceFee
        {
            get { return _ambulanceFee; }
            set { _ambulanceFee = value; }
        }


        //Spouse Variables
        string _spousestatus;
        public string SpouseStatus
        {
            get { return _spousestatus; }
            set { _spousestatus = value; }
        }
        string _spousename;
        public string SpouseName
        {
            get { return _spousename; }
            set { _spousename = value; }
        }

        string _spouseoccupation;
        public string SpouseOccupation
        {
            get { return _spouseoccupation; }
            set { _spouseoccupation = value; }
        }

        string _spousenric;
        public string SpouseNRICNo
        {
            get { return _spousenric; }
            set { _spousenric = value; }
        }

        string _spousedob;
        public string SpouseDOB
        {
            get { return _spousedob; }
            set { _spousedob = value; }
        }

        //Child 1
        string _childcount;
        public string ChildCount
        {
            get { return _childcount; }
            set { _childcount = value; }
        }

        string _childname1;
        public string ChildName1
        {
            get { return _childname1; }
            set { _childname1 = value; }
        }

        string _childnric1;
        public string ChildNRICNo1
        {
            get { return _childnric1; }
            set { _childnric1 = value; }
        }

        string _childdob1;
        public string ChildDOB1
        {
            get { return _childdob1; }
            set { _childdob1 = value; }
        }

        //Child 2
        string _childname2;
        public string ChildName2
        {
            get { return _childname2; }
            set { _childname2 = value; }
        }

        string _childnric2;
        public string ChildNRICNo2
        {
            get { return _childnric2; }
            set { _childnric2 = value; }
        }

        string _childdob2;
        public string ChildDOB2
        {
            get { return _childdob2; }
            set { _childdob2 = value; }
        }

        //Child 3
        string _childname3;
        public string ChildName3
        {
            get { return _childname3; }
            set { _childname3 = value; }
        }

        string _childnric3;
        public string ChildNRICNo3
        {
            get { return _childnric3; }
            set { _childnric3 = value; }
        }

        string _childdob3;
        public string ChildDOB3
        {
            get { return _childdob3; }
            set { _childdob3 = value; }
        }

        //Child 4
        string _childname4;
        public string ChildName4
        {
            get { return _childname4; }
            set { _childname4 = value; }
        }

        string _childnric4;
        public string ChildNRICNo4
        {
            get { return _childnric4; }
            set { _childnric4 = value; }
        }

        string _childdob4;
        public string ChildDOB4
        {
            get { return _childdob4; }
            set { _childdob4 = value; }
        }

        //Child 5
        string _childname5;
        public string ChildName5
        {
            get { return _childname5; }
            set { _childname5 = value; }
        }

        string _childnric5;
        public string ChildNRICNo5
        {
            get { return _childnric5; }
            set { _childnric5 = value; }
        }

        string _childdob5;
        public string ChildDOB5
        {
            get { return _childdob5; }
            set { _childdob5 = value; }
        }

        #endregion

        #region Tax Invoice Variables
        string _gstRegNumber;
        public string GSTRegNumber
        {
            get { return _gstRegNumber; }
            set { _gstRegNumber = value; }
        }

        string _transDate;
        public string TransactionDate
        {
            get { return _transDate; }
            set { _transDate = value; }
        }

        string _branchTerritory;
        public string BranchTerritory
        {
            get { return _branchTerritory; }
            set { _branchTerritory = value; }
        }

        string _accountAgency;
        public string AcountAgency
        {
            get { return _accountAgency; }
            set { _accountAgency = value; }
        }


        string _cardType;
        public string CardType
        {
            get { return _cardType; }
            set { _cardType = value; }
        }

        string _cardLastFourDigit;
        public string CardLastFourDigit
        {
            get { return _cardLastFourDigit; }
            set { _cardLastFourDigit = value; }
        }
        #endregion

        public EtiqaPAInsurancePDFOutput()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public bool GenerateAllOuput(out string[] fileList)
        {
            fileList = new string[2];
            bool _retValue = false;
            try
            {
                fileList[0] = EtiqaTaxInvoiceOutputSample();
                fileList[1] = EtiqaScheduleOutputSample();
                _retValue = true;
            }
            catch (Exception Ex)
            {
                _retValue = false;
            }

            return _retValue;
        }

        public string EtiqaScheduleOutputSample()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();
            document.Info.Title = _schedulewritingpagetitle;

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);


            // Create a font
            XFont font = new XFont("Verdana", 7, XFontStyle.Bold);
            XFont fontNormal = new XFont("Arial", 8, XFontStyle.Regular);
            XFont fontNormalB = new XFont("Arial", 8, XFontStyle.Bold);
            XFont fontBig = new XFont("Arial", 9, XFontStyle.Regular);
            XFont fontBigB = new XFont("Arial", 9, XFontStyle.Bold);
            XColor _xcolor = new XColor();
            _xcolor.R = 0;
            _xcolor.G = 0;
            _xcolor.B = 0;
            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(20, 10, 500, 100);
            XPen _pen = new XPen(_xcolor);
            _pen.Width = 1;

            XPen _pen2 = new XPen(XColors.Black, 0);

            int curX = 45;
            int curY = 35;

            gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "images\\pdf\\header_etiqa_sch.png"), new XRect(curX, curY, 520, 106));
            curY += 85;

            int _boxWidth = Convert.ToInt32(page.Width.Value) - 100;

            //DrawBoxWithText(gfx, _xcolor, curX, curY, _boxWidth, 20, 0.8d, "THE SCHEDULE", "Verdana", 10.0d, XFontStyle.Bold);
            curY += 23;

            gfx.DrawString("ISSUED ON", fontBigB, XBrushes.Black, new XRect(curX + 3, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_issuedOn, fontBigB, XBrushes.Black, new XRect(curX + 58, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("POLICY NO.", fontBigB, XBrushes.Black, new XRect(curX + 385, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_policyNumber, fontBigB, XBrushes.Black, new XRect(curX + 447, curY, 100, 20), XStringFormat.TopLeft);

            curY += 25;

            if (isPromo)
            {
                DrawBoxWithText(gfx, _xcolor, curX + 3, curY, 515, 175, 2.0d, "", "Verdana", 6.0, XFontStyle.Bold);
            }
            else
            {
                DrawBoxWithText(gfx, _xcolor, curX + 3, curY, 515, 160, 2.0d, "", "Verdana", 6.0, XFontStyle.Bold);
            }

            DrawBoxWithText(gfx, _xcolor, curX + 3, curY, 120, 20, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);
            DrawBoxWithText(gfx, _xcolor, curX + 123, curY, 250, 20, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);
            DrawBoxWithText(gfx, _xcolor, curX + 373, curY, 145, 20, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);

            gfx.DrawString("Agency     ", fontNormalB, XBrushes.Black, new XRect(curX + 8, curY + 5, 120, 20), XStringFormat.TopLeft);
            //gfx.DrawString("    000598", fontNormal, XBrushes.Black, new XRect(curX + 78, curY + 5, 120, 20), XStringFormat.TopLeft);
            gfx.DrawString("    " + _agency, fontNormal, XBrushes.Black, new XRect(curX + 78, curY + 5, 120, 20), XStringFormat.TopLeft);
            gfx.DrawString("Class of Policy", fontNormalB, XBrushes.Black, new XRect(curX + 128, curY + 5, 250, 20), XStringFormat.TopLeft);
            gfx.DrawString(_classOfPolicy, fontNormal, XBrushes.Black, new XRect(curX + 223, curY + 5, 250, 20), XStringFormat.TopLeft);
            gfx.DrawString("Acceptance Date", fontNormalB, XBrushes.Black, new XRect(curX + 378, curY + 5, 250, 20), XStringFormat.TopLeft);
            gfx.DrawString(_acceptanceDate, fontNormal, XBrushes.Black, new XRect(curX + 448, curY + 5, 100, 20), XStringFormat.TopLeft);

            curY += 20;
            DrawBoxWithText(gfx, _xcolor, curX + 3, curY, 120, 20, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);
            DrawBoxWithText(gfx, _xcolor, curX + 123, curY, 395, 20, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);

            gfx.DrawString("Account     ", fontNormalB, XBrushes.Black, new XRect(curX + 8, curY + 5, 120, 20), XStringFormat.TopLeft);
            gfx.DrawString("    " + _account, fontNormal, XBrushes.Black, new XRect(curX + 78, curY + 5, 120, 20), XStringFormat.TopLeft);
            gfx.DrawString("Period of Insurance", fontNormalB, XBrushes.Black, new XRect(curX + 128, curY + 5, 390, 20), XStringFormat.TopLeft);
            gfx.DrawString("From " + _startPeriod + " to " + _endPeriod + "  (both dates inclusive)", fontNormal, XBrushes.Black, new XRect(curX + 223, curY + 5, 390, 20), XStringFormat.TopLeft);

            curY += 20;
            DrawBoxWithText(gfx, _xcolor, curX + 3, curY, 120, 50, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);
            DrawBoxWithText(gfx, _xcolor, curX + 123, curY, 395, 20, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);
            DrawBoxWithText(gfx, _xcolor, curX + 123, curY + 20, 395, 30, 1.25, "", "Verdana", 6.0, XFontStyle.Bold);

            gfx.DrawString("Client", fontNormalB, XBrushes.Black, new XRect(curX + 8, curY + 5, 120, 20), XStringFormat.TopLeft);
            gfx.DrawString("Insured Name", fontNormalB, XBrushes.Black, new XRect(curX + 128, curY + 5, 390, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customerName.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 223, curY + 5, 390, 20), XStringFormat.TopLeft);

            curY += 20;
            gfx.DrawString("Insured Address", fontNormalB, XBrushes.Black, new XRect(curX + 128, curY + 5, 390, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customerAddress1.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 223, curY + 4, 390, 15), XStringFormat.TopLeft);
            gfx.DrawString(_customerAddress2.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 223, curY + 17, 390, 15), XStringFormat.TopLeft);

            curY += 30;
            double Premium = (Convert.ToDouble(_totalDueInvoice) / 107 * 100);
            gfx.DrawString("Annual Premium", fontNormalB, XBrushes.Black, new XRect(curX + 8, curY + 5, 120, 18), XStringFormat.TopLeft);
            gfx.DrawString("S$", fontNormal, XBrushes.Black, new XRect(curX + 350, curY + 5, 120, 18), XStringFormat.TopLeft);
            gfx.DrawString(String.Format("{0:0,0.00}", Premium), fontNormal, XBrushes.Black, new XRect(curX + 480, curY + 5, 120, 18), XStringFormat.TopLeft);

            curY += 18;
            DrawBoxWithText(gfx, _xcolor, curX + 5, curY, 510, 0, .75, "", "Verdana", 6.0, XFontStyle.Bold);
            gfx.DrawString("Subtotal:", fontNormalB, XBrushes.Black, new XRect(curX + 300, curY + 3, 120, 16), XStringFormat.TopLeft);
            gfx.DrawString("S$", fontNormalB, XBrushes.Black, new XRect(curX + 350, curY + 3, 120, 16), XStringFormat.TopLeft);
            gfx.DrawString(String.Format("{0:0,0.00}", Premium), fontNormalB, XBrushes.Black, new XRect(curX + 480, curY + 3, 120, 16), XStringFormat.TopLeft);

            curY += 16;
            double GSTAmount = (Convert.ToDouble(_totalDueInvoice) / 107 * 7);
            DrawBoxWithText(gfx, _xcolor, curX + 5, curY + 10, 510, 0, .75, "", "Verdana", 6.0, XFontStyle.Bold);
            gfx.DrawString("Add GST (7.00%):", fontNormalB, XBrushes.Black, new XRect(curX + 275, curY, 120, 16), XStringFormat.TopLeft);
            gfx.DrawString("S$", fontNormalB, XBrushes.Black, new XRect(curX + 350, curY, 120, 16), XStringFormat.TopLeft);
            gfx.DrawString(String.Format("{0:0,0.00}", GSTAmount), fontNormal, XBrushes.Black, new XRect(curX + 480, curY, 120, 16), XStringFormat.TopLeft);

            if (isPromo)
            {
                double discountprice = (Convert.ToSingle(_totalDueInvoice) * .10);
                curY += 16;
                DrawBoxWithText(gfx, _xcolor, curX + 5, curY + 12, 510, 1, .75, "", "Verdana", 6.0, XFontStyle.Bold);
                gfx.DrawString("Promo Discount (10%):", fontNormalB, XBrushes.Black, new XRect(curX + 255, curY, 120, 16), XStringFormat.TopLeft);
                gfx.DrawString("S$", fontNormalB, XBrushes.Black, new XRect(curX + 350, curY, 120, 16), XStringFormat.TopLeft);
                gfx.DrawString("[" + String.Format("{0:0,0.00}" + "]", discountprice), fontNormal, XBrushes.Black, new XRect(curX + 480, curY, 120, 16), XStringFormat.TopLeft);

                curY += 18;
                DrawBoxWithText(gfx, _xcolor, curX + 5, curY + 12, 510, 1, .75, "", "Verdana", 6.0, XFontStyle.Bold);
                gfx.DrawString("Total Due:", fontNormalB, XBrushes.Black, new XRect(curX + 295, curY, 120, 18), XStringFormat.TopLeft);
                gfx.DrawString("S$", fontNormalB, XBrushes.Black, new XRect(curX + 350, curY, 120, 18), XStringFormat.TopLeft);
                gfx.DrawString(_newpremium, fontNormalB, XBrushes.Black, new XRect(curX + 480, curY, 120, 18), XStringFormat.TopLeft);
            }
            else
            {
                curY += 18;
                DrawBoxWithText(gfx, _xcolor, curX + 5, curY + 12, 510, 1, .75, "", "Verdana", 6.0, XFontStyle.Bold);
                gfx.DrawString("Total Due:", fontNormalB, XBrushes.Black, new XRect(curX + 295, curY, 120, 18), XStringFormat.TopLeft);
                gfx.DrawString("S$", fontNormalB, XBrushes.Black, new XRect(curX + 350, curY, 120, 18), XStringFormat.TopLeft);
                gfx.DrawString(_totalDueInvoice, fontNormalB, XBrushes.Black, new XRect(curX + 480, curY, 120, 18), XStringFormat.TopLeft);
            }


            curY += 30;

            if (_planname.Trim() == "Elite")
            {
                _totalLossOfOneLimb = "150,000";
                _totalLossOfHearingOne = "60,000";
                _totalLossElbow = "45,000";
                _totalLossOneThumb = "45,000";
                _totalLossOneForefinger = "30,000";
                _totalLossAnyFinger = "15,000";
                _totalLossAnyToe = "6,000";

                _compassionateCash = "3,000";
                _medExpPerAccident = "3,000";
                _outpatientCash = "50";
                _chineseMedExp = "300";
                _snatchTheft = "300";
                _dentalTreatment = "1,500";
                _kidnapBenefit = "2,000";
                _ambulanceFee = "300";
            }

            gfx.DrawString("BENEFITS", fontBigB, XBrushes.Black, new XRect(curX, curY, 500, 20), XStringFormat.Center);
            curY += 20;
            gfx.DrawString(_planname + " Plan", fontNormalB, XBrushes.Black, new XRect(curX + 160, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString("Table of Limits (S$)", fontNormalB, XBrushes.Black, new XRect(curX + 435, curY, 200, 20), XStringFormat.TopLeft);

            curY += 10;
            DrawBoxWithText(gfx, _xcolor, curX + 3, curY, 510, 15, .75, "", "Verdana", 6.0, XFontStyle.Bold);
            gfx.DrawLine(_pen2, curX + 5, curY, 505, curY);
            DrawBoxWithText(gfx, _xcolor, curX + 2, curY, _boxWidth, 14, 0.8d, "", "Verdana", 6.0, XFontStyle.Regular, XBrushes.LightGray);
            gfx.DrawString("Benefits", fontNormalB, XBrushes.Black, new XRect(curX + 10, curY + 3, 200, 15), XStringFormat.TopLeft);

            curY += 15;
            //gfx.DrawLine(_pen2, curX + 8, curY, 555, curY);
            gfx.DrawString("Section 1 - Accidental Death", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx.DrawString("We shall pay the Benefit Amount if during the Period of Insurance, you have sustained Bodily Injury which results ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_accidentalDeath, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;
            gfx.DrawString("in Accidental Death within fifty two (52) weeks from the date of Accident.", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("Section 2 - Permanent Disability due to Accident", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx.DrawString("If during the Period of Insurance, you have sustained Bodily Injury which results in Permanent Disability within fifty ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("two (52) weeks from the date of Accident, we shall pay the relevant Benefit Amount as specified below:", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("a) Permanent Total Paralysis or complete insanity or injuries resulting in being permanently bedridden.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_permanentDisability, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("b) Permanent Total Loss of sight of both eyes or use of both hands or both feet or combination of these.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOfSight, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("c) Permanent Total Loss of speech.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOfSpeech, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("d) Permanent Total Loss of hearing in both ears.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOfHearingBoth, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("e) Permanent Total Loss of sight of one eye or use of one limb.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOfOneLimb, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("f) Permanent Total Loss of hearing in one ear.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOfHearingOne, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("g) Permanent Total Loss of use of a shoulder, elbow, hip, knee, ankle or wrist.", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossElbow, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("h) Permanent Total Loss of use or loss by amputation of:", fontNormal, XBrushes.Black, new XRect(curX + 20, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("i) One thumb.", fontNormal, XBrushes.Black, new XRect(curX + 25, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOneThumb, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("ii) One forefinger.", fontNormal, XBrushes.Black, new XRect(curX + 25, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossOneForefinger, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("iii) Any other finger or one big toe.", fontNormal, XBrushes.Black, new XRect(curX + 25, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossAnyFinger, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("iv) Any other toe.", fontNormal, XBrushes.Black, new XRect(curX + 25, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_totalLossAnyToe, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;


            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("Section 3 - Compassionate Cash", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Lump sum cash benefit to the family in the event of accidental death to the insured. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_compassionateCash, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("Section 4 - In-hospital Medical Expenses (any one accident)", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Reimbursement based on per accident for medical and surgical treatment. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_medExpPerAccident, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("Section 5 - Hospital Confinement Allowance", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("A cash allowance as stated in the table will be paid up to 100 days if confined in a hospital for more than 24 hours", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString("S$" + _hospitalConfinement + " per day", fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;
            gfx.DrawString("for treatment for an accident. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString("up to 100 days", fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("Section 6 - Outpatient Cash Benefit", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Lump sum cash irrespective of amount shown in receipt, for your emergency treatment at a registered clinic /", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_outpatientCash, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;
            gfx.DrawString("hospital as a result of an accident. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx.DrawLine(_pen2, curX + 8, curY, 545, curY);
            gfx.DrawString("Section 7 - Outpatient Medical Expenses", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("If the cost of your emergency treatment at a registered clinic / hospital exceeds the amount payable in Section 6, we", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx.DrawString(_outpatientMedExp, fontNormal, XBrushes.Black, new XRect(curX + 450, curY - 2, 40, 20), XStringFormat.Center);
            curY += 12;
            gfx.DrawString("will reimburse the additional amount up to the maximum limit shown. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);

            if (isPromo)
            {
                curY += 15;
            }
            else
            {
                curY += 25;
            }
            gfx.DrawString("Page 1 of 2", fontNormal, XBrushes.Black, new XRect(curX + 480, curY, 200, 20), XStringFormat.TopLeft);


            //Etiqa_Schedule_writings_New.pdf
            //HttpUtility _server = new HttpUtility();
            //PdfDocument inputDocument = PdfReader.Open(AppDomain.CurrentDomain.BaseDirectory + "images\\pdf\\Etiqa_Schedule_writings_New.pdf", PdfDocumentOpenMode.Import);
            //document.AddPage(inputDocument.Pages[0]);
            //document.AddPage(inputDocument.Pages[1]);

            //PAGE 2
            PdfPage page2 = document.AddPage();
            XGraphics gfx2 = XGraphics.FromPdfPage(page2);

            curX = 45;
            curY = 45;

            gfx2.DrawLine(_pen2, curX + 8, curY, 535, curY);
            gfx2.DrawString("Section 8 - Chinese Medical Expenses", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Reimbursement for cost of seeking treatment by a certified / registered Chinese Medical Practitioner in the event of", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_chineseMedExp, fontNormal, XBrushes.Black, new XRect(curX + 460, curY - 2, 20, 20), XStringFormat.Center);
            curY += 12;
            gfx2.DrawString("any accidental bodily injury for any one accident subject to original receipt being provided. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx2.DrawLine(_pen2, curX + 8, curY, 535, curY);
            gfx2.DrawString("Section 9 - Snatch Theft", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Lump sum cash for bodily injury caused by snatch thief, (with police report).", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_snatchTheft, fontNormal, XBrushes.Black, new XRect(curX + 460, curY - 2, 20, 20), XStringFormat.Center);
            curY += 12;

            gfx2.DrawLine(_pen2, curX + 8, curY, 535, curY);
            gfx2.DrawString("Section 10 - Accidental Dental Treatment", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Reimbursement for corrective or treatment of injury or damage to sound natural teeth due to accident.", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_dentalTreatment, fontNormal, XBrushes.Black, new XRect(curX + 460, curY - 4, 20, 20), XStringFormat.Center);
            curY += 12;

            gfx2.DrawLine(_pen2, curX + 8, curY, 535, curY);
            gfx2.DrawString("Section 11 - Kidnap Benefit with police report including validation of kidnap by police", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Lump sum payment on the necessary expenses incurred for hiring of a licensed private investigator appointed with", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("the consent of the Company incurred by your family members in the event of being kidnapped. This benefit is ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_kidnapBenefit, fontNormal, XBrushes.Black, new XRect(curX + 460, curY - 2, 20, 20), XStringFormat.Center);
            curY += 12;
            gfx2.DrawString("payable subject to verification and confirmation by the police that a kidnap has taken place. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx2.DrawLine(_pen2, curX + 8, curY, 535, curY);
            gfx2.DrawString("Section 12 - Ambulance Fees", fontNormalB, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Reimbursement of the actual fee (up to a maximum limit as specified) incurred for the use of ambulance services,", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_ambulanceFee, fontNormal, XBrushes.Black, new XRect(curX + 460, curY - 2, 20, 20), XStringFormat.Center);
            curY += 12;
            gfx2.DrawString("subject to original receipt being provided. ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;

            gfx2.DrawLine(_pen2, curX + 8, curY, 535, curY);
            gfx2.DrawString("NOTE:", font, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("a) Children benefit (each child) is covered at 20% of adult benefit under Section 1 to 4 only.", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("b) To be eligible under this product, the child named in the Schedule, must be a Singapore Citizen, or Permanent Resident of Singapore, or", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Foreigners with valid Dependant’s Pass or Long-Term Visit Pass of at least one(1) year of age and not more than twenty four(24) years of age", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("on the Effective Date of Insurance.", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 25;

            gfx2.DrawString("INSURED", fontBigB, XBrushes.Black, new XRect(curX, curY, 500, 20), XStringFormat.Center);
            curY += 20;
            gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
            gfx2.DrawLine(_pen2, curX + 15, curY, curX + 15, curY + 77);
            gfx2.DrawLine(_pen2, 525, curY, 525, curY + 77);

            if (_spousestatus == "Yes")
            {
                gfx2.DrawLine(_pen2, curX + 280, curY, curX + 280, curY + 77);
            }

            if (_spousestatus == "No")
            {
                gfx2.DrawString("Insured Person", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 5, 200, 20), XStringFormat.TopLeft);
            }
            else if (_spousestatus == "Yes")
            {
                gfx2.DrawString("Insured Person 1", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 5, 200, 20), XStringFormat.TopLeft);
                gfx2.DrawString("Insured Person 2", fontNormalB, XBrushes.Black, new XRect(curX + 285, curY + 5, 200, 20), XStringFormat.TopLeft);
            }
            curY += 17;
            gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
            gfx2.DrawString("Name", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 4, 100, 15), XStringFormat.TopLeft);
            gfx2.DrawString(_customerName.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 4, 300, 15), XStringFormat.TopLeft);
            if (_spousestatus == "Yes")
            {
                gfx2.DrawString(_spousename.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 4, 220, 15), XStringFormat.TopLeft);
            }

            gfx2.DrawString("NRIC No.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 19, 100, 15), XStringFormat.TopLeft);
            gfx2.DrawString(_nric.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 19, 300, 15), XStringFormat.TopLeft);
            if (_spousestatus == "Yes")
            {
                gfx2.DrawString(_spousenric.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 19, 220, 15), XStringFormat.TopLeft);
            }

            gfx2.DrawString("Date of Birth.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 34, 100, 15), XStringFormat.TopLeft);
            gfx2.DrawString(_dob.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 34, 300, 15), XStringFormat.TopLeft);
            if (_spousestatus == "Yes")
            {
                gfx2.DrawString(_spousedob.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 34, 220, 15), XStringFormat.TopLeft);
            }

            gfx2.DrawString("Occupation", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 49, 100, 15), XStringFormat.TopLeft);
            gfx2.DrawString(_occupation.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 49, 300, 15), XStringFormat.TopLeft);
            if (_spousestatus == "Yes")
            {
                gfx2.DrawString(_spouseoccupation.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 49, 220, 15), XStringFormat.TopLeft);
            }

            gfx2.DrawLine(_pen2, curX + 15, curY + 60, 525, curY + 60);

            //Childs
            Int16 _NoofChilds = Convert.ToInt16(_childcount);
            if (_NoofChilds > 0)
            {
                curY += 80;
                gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
                gfx2.DrawLine(_pen2, curX + 15, curY, curX + 15, curY + 62);
                gfx2.DrawLine(_pen2, 525, curY, 525, curY + 62);

                if (_NoofChilds > 1)
                {
                    gfx2.DrawLine(_pen2, curX + 280, curY, curX + 280, curY + 62);
                }

                gfx2.DrawString("Child 1", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 5, 200, 20), XStringFormat.TopLeft);
                if (_NoofChilds > 1)
                {
                    gfx2.DrawString("Child 2", fontNormalB, XBrushes.Black, new XRect(curX + 285, curY + 5, 200, 20), XStringFormat.TopLeft);
                }
                curY += 17;
                gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
                gfx2.DrawString("Name", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 4, 100, 15), XStringFormat.TopLeft);
                gfx2.DrawString(_childname1.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 4, 300, 15), XStringFormat.TopLeft);
                if (_NoofChilds > 1)
                {
                    gfx2.DrawString(_childname2.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 4, 220, 15), XStringFormat.TopLeft);
                }

                gfx2.DrawString("NRIC No.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 19, 100, 15), XStringFormat.TopLeft);
                gfx2.DrawString(_childnric1.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 19, 300, 15), XStringFormat.TopLeft);
                if (_NoofChilds > 1)
                {
                    gfx2.DrawString(_childnric2.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 19, 220, 15), XStringFormat.TopLeft);
                }

                gfx2.DrawString("Date of Birth.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 34, 100, 15), XStringFormat.TopLeft);
                gfx2.DrawString(_childdob1.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 34, 300, 15), XStringFormat.TopLeft);
                if (_NoofChilds > 1)
                {
                    gfx2.DrawString(_childdob2.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 34, 220, 15), XStringFormat.TopLeft);
                }

                gfx2.DrawLine(_pen2, curX + 15, curY + 45, 525, curY + 45);

                if (_NoofChilds > 2)
                {
                    curY += 60;
                    gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
                    gfx2.DrawLine(_pen2, curX + 15, curY, curX + 15, curY + 62);
                    gfx2.DrawLine(_pen2, 525, curY, 525, curY + 62);

                    if (_NoofChilds > 3)
                    {
                        gfx2.DrawLine(_pen2, curX + 280, curY, curX + 280, curY + 62);
                    }

                    gfx2.DrawString("Child 3", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 5, 200, 20), XStringFormat.TopLeft);
                    if (_NoofChilds > 3)
                    {
                        gfx2.DrawString("Child 4", fontNormalB, XBrushes.Black, new XRect(curX + 285, curY + 5, 200, 20), XStringFormat.TopLeft);
                    }
                    curY += 17;
                    gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
                    gfx2.DrawString("Name", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 4, 100, 15), XStringFormat.TopLeft);
                    gfx2.DrawString(_childname3.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 4, 300, 15), XStringFormat.TopLeft);
                    if (_NoofChilds > 3)
                    {
                        gfx2.DrawString(_childname4.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 4, 220, 15), XStringFormat.TopLeft);
                    }

                    gfx2.DrawString("NRIC No.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 19, 100, 15), XStringFormat.TopLeft);
                    gfx2.DrawString(_childnric3.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 19, 300, 15), XStringFormat.TopLeft);
                    if (_NoofChilds > 3)
                    {
                        gfx2.DrawString(_childnric4.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 19, 220, 15), XStringFormat.TopLeft);
                    }

                    gfx2.DrawString("Date of Birth.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 34, 100, 15), XStringFormat.TopLeft);
                    gfx2.DrawString(_childdob3.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 34, 300, 15), XStringFormat.TopLeft);
                    if (_NoofChilds > 3)
                    {
                        gfx2.DrawString(_childdob4.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 285, curY + 34, 220, 15), XStringFormat.TopLeft);
                    }

                    gfx2.DrawLine(_pen2, curX + 15, curY + 45, 525, curY + 45);
                }


                if (_NoofChilds > 4)
                {
                    curY += 60;
                    gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
                    gfx2.DrawLine(_pen2, curX + 15, curY, curX + 15, curY + 62);
                    gfx2.DrawLine(_pen2, 525, curY, 525, curY + 62);

                    gfx2.DrawString("Child 5", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 5, 200, 20), XStringFormat.TopLeft);

                    curY += 17;
                    gfx2.DrawLine(_pen2, curX + 15, curY, 525, curY);
                    gfx2.DrawString("Name", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 4, 100, 15), XStringFormat.TopLeft);
                    gfx2.DrawString(_childname5.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 4, 300, 15), XStringFormat.TopLeft);

                    gfx2.DrawString("NRIC No.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 19, 100, 15), XStringFormat.TopLeft);
                    gfx2.DrawString(_childnric5.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 19, 300, 15), XStringFormat.TopLeft);

                    gfx2.DrawString("Date of Birth.", fontNormalB, XBrushes.Black, new XRect(curX + 20, curY + 34, 100, 15), XStringFormat.TopLeft);
                    gfx2.DrawString(_childdob5.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 90, curY + 34, 300, 15), XStringFormat.TopLeft);

                    gfx2.DrawLine(_pen2, curX + 15, curY + 45, 525, curY + 45);
                }
            }

            if (_NoofChilds == 0)
            {
                curY += 80;
            }
            else if (_NoofChilds <= 2)
            {
                curY += 60;
            }
            else if (_NoofChilds <= 4)
            {
                curY += 40;
            }
            else if (_NoofChilds > 4)
            {
                curY += 20;
            }

            curY += 30;

            gfx2.DrawString("Policy Owners’ Protection Scheme", font, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("This policy is protected under the Policy Owners’ Protection Scheme which is administered by the Singapore Deposit Insurance ", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Corporation (SDIC). Coverage for your policy is automatic and no further action is required from you. For more information on the", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("types of benefits that are covered under the scheme as well as the limits of coverage, where applicable, please contact your", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("insurer or visit the GIA / LIA or SDIC websites (www.gia.org.sg or www.lia.org.sg or www.sdic.org.sg).", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 200, 20), XStringFormat.TopLeft);
          
            XFont _textFont = new XFont("Verdana", 8, XFontStyle.Bold);

            curY += 30;
            gfx2.DrawString("Signed for and on behalf of the company", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;
            gfx2.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "images\\pdf\\etiqa_signature.jpg"), curX + 50, curY, 80, 40);
            curY += 35;
            gfx2.DrawString("_______________________________", _textFont, XBrushes.Black, new XRect(curX + 15, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;
            gfx2.DrawString("Authorized Signature", fontNormal, XBrushes.Black, new XRect(curX + 15, curY, 50, 15), XStringFormat.TopLeft);


            if (_NoofChilds == 0)
            {
                //curY += 245;
                curY += 215;
            }
            else if (_NoofChilds <= 2)
            {
                //curY += 170;
                curY += 140;
            }
            else if (_NoofChilds <= 4)
            {
                //curY += 110;
                curY += 80;
            }
            else if (_NoofChilds > 4)
            {
                curY += 20;
            }
            gfx2.DrawString("Page 2 of 2", fontNormal, XBrushes.Black, new XRect(curX + 480, curY, 200, 20), XStringFormat.TopLeft);


            string _filePath = GetFilePath();
            string filename = _filePath + "Etiqa_PA_Schedule_" + _proposalId + ".pdf";

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            document.Save(filename);
            stream.Close();
            document.Close();
            return filename;
        }


        public string EtiqaTaxInvoiceOutputSample()
        {


            // Create a new PDF document
            PdfDocument document = new PdfDocument();
            document.Info.Title = _taxinvoicepagetitle;

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Create a font
            XFont font = new XFont("Verdana", 9, XFontStyle.Bold);

            XColor _xcolor = new XColor();
            _xcolor.R = 0;
            _xcolor.G = 0;
            _xcolor.B = 0;
            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(20, 10, 500, 100);
            XPen _pen = new XPen(_xcolor);

            int curX = 45;
            int curY = 50;


            gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "images\\pdf\\header_etiqa_tax.png"), new XRect(curX, curY, 520, 111));
            curY += 85;

            int _boxWidth = Convert.ToInt32(page.Width.Value) - 100;

            //DrawBoxWithText(gfx, _xcolor, curX, curY, _boxWidth, 19, 0.8d, "", "Verdana", 6.0, XFontStyle.Regular, XBrushes.Yellow);
            //DrawBoxWithText(gfx, _xcolor, curX, curY, _boxWidth, 20, 1.0d, "TAX INVOICE", "Verdana", 9.0d, XFontStyle.Bold);
            curY += 25;

            _xcolor.R = 255;
            _xcolor.G = 255;
            _xcolor.B = 255;

            DrawBoxWithText(gfx, _xcolor, curX, curY, _boxWidth, 20, 0, "Debit Note", "Verdana", 9.0d, XFontStyle.Bold);
            curY += 20;

            XFont _textFontB = new XFont("Verdana", 8, XFontStyle.Bold);
            XFont _textFontR = new XFont("Verdana", 8, XFontStyle.Regular);
            gfx.DrawString("GST Reg. No. " + _gstRegNumber, _textFontB, XBrushes.Black, new XRect(curX, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString("Transaction/Due Date : " + (Convert.ToDateTime(_transDate)).ToString("dd/MM/yyyy"), _textFontB, XBrushes.Black, new XRect(curX + 330, curY, 50, 15), XStringFormat.TopLeft);
            curY += 40;

            gfx.DrawString(_customerName.ToUpper(), _textFontB, XBrushes.Black, new XRect(curX + 30, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;

            string _tmpAddress1 = "";
            string[] _addresslist = _customerAddress1.Split(',');
            for (int _d = 0; _d < _addresslist.Length - 1; _d++)
            {
                if (_d == 0 || _d == 1)
                {
                    _tmpAddress1 += _addresslist[_d] + ", ";
                    //curY += 10;
                }
                else if (_d == 2)
                {
                    _customerAddress2 = _addresslist[_d].Trim() + ", " + _customerAddress2;
                }
                else
                {
                    break;
                }
            }
            _customerAddress1 = _tmpAddress1;

            gfx.DrawString(_customerAddress1.ToUpper(), _textFontR, XBrushes.Black, new XRect(curX + 30, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;
            gfx.DrawString(_customerAddress2.ToUpper(), _textFontR, XBrushes.Black, new XRect(curX + 30, curY, 50, 15), XStringFormat.TopLeft);
            curY += 30;

            string[,] _arrNewData = new string[,]{{"Type Of Policy", _classOfPolicy},
                          {"Policy Number", _policyNumber},
                          {"Period of Cover", "From " + _startPeriod + " to " + _endPeriod + "(both dates inclusive)"},
                          {"Main Insured's Name", _customerName},
                          {"Insured's Address", _customerAddress1},
                          {"", _customerAddress2},
                          {"Branch / Territory",_branchTerritory},
                          {"Account / Agency",_accountAgency}};

            int[] _colArrWidth = { 140, 300 };

            _xcolor.R = 0;
            _xcolor.G = 0;
            _xcolor.B = 0;

            DrawBoxWithTextList(gfx, _xcolor, curX, curY, _boxWidth, 12, 8, 2, 1.5d, "Verdana", 8.7, XFontStyle.Regular, _arrNewData, _colArrWidth);

            curY += 180;
            if (isPromo)
            {
                double discountprice = (Convert.ToSingle(_totalDueInvoice) * .10);
                string[,] _arrPremiumData = new string[,]{{"Annual Premium (Inclusive of 7% GST)", "           S$        "+_totalDueInvoice},
                          {"Promo Discount 10% ", "           S$        ["+String.Format("{0:0,0.00}", discountprice) + "]"},{"", "_________________________"},
                          {"Total Due", "           S$        "+_newpremium},
                          };

                _xcolor.R = 0;
                _xcolor.G = 0;
                _xcolor.B = 0;
                int[] _colPremiumArrWidth = { 300, 150 };
                DrawBoxWithTextList(gfx, _xcolor, curX, curY, _boxWidth, 10, 4, 2, 2.0d, "Verdana", 9, XFontStyle.Regular, _arrPremiumData, _colPremiumArrWidth);

            }
            else
            {
                string[,] _arrPremiumData = new string[,]{{"Annual Premium (Inclusive of 7% GST)", "           S$        "+_totalDueInvoice},{"", "_________________________"},
                          {"Total Due", "           S$        "+_totalDueInvoice},
                          };

                _xcolor.R = 0;
                _xcolor.G = 0;
                _xcolor.B = 0;
                int[] _colPremiumArrWidth = { 300, 150 };
                DrawBoxWithTextList(gfx, _xcolor, curX, curY, _boxWidth, 10, 3, 2, 2.0d, "Verdana", 9, XFontStyle.Regular, _arrPremiumData, _colPremiumArrWidth);

            }

            curY += 90;
            gfx.DrawString("Paid via " + _cardType + " XXXX XXXX XXXX XXXX" + _cardLastFourDigit, _textFontB, XBrushes.Black, new XRect(curX, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;
            gfx.DrawString("Signed for and on behalf of the company", _textFontR, XBrushes.Black, new XRect(curX, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;
            gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "images\\pdf\\etiqa_signature.jpg"), curX + 50, curY, 80, 40);
            curY += 35;
            gfx.DrawString("_______________________________", _textFontB, XBrushes.Black, new XRect(curX, curY, 50, 15), XStringFormat.TopLeft);
            curY += 10;
            gfx.DrawString("Authorized Signature", _textFontR, XBrushes.Black, new XRect(curX, curY, 50, 15), XStringFormat.TopLeft);

            string _filePath = GetFilePath();
            string filename = _filePath + "Etiqa_PA_TaxInvoice_" + _proposalId + ".pdf";
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            document.Save(filename);
            stream.Close();
            document.Close();

            return filename;
        }

        private void DrawBoxOnly(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, double borderWidth)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = width;
            _rect.Height = height;
            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            _objG.DrawRectangle(_pen, _rect);
        }

        private void DrawBoxWithText(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, double borderWidth, string strText, string strFontName, double fontSize, XFontStyle xFontStyle)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = width;
            _rect.Height = height;
            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            XFont font = new XFont(strFontName, fontSize, xFontStyle);
            _objG.DrawRectangle(_pen, _rect);
            _objG.DrawString(strText, font, XBrushes.Black, _rect, XStringFormats.Center);
        }

        private void DrawBoxWithText(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, double borderWidth, string strText, string strFontName, double fontSize, XFontStyle xFontStyle, XSolidBrush xSolidBrush)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x + 1;
            _rect.Y = y + 1;
            _rect.Width = width - 2;
            _rect.Height = height - 1;


            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            XFont font = new XFont(strFontName, fontSize, xFontStyle);
            //_objG.DrawRectangle(_pen, _rect);
            _objG.DrawRectangle(xSolidBrush, _rect);
            _objG.DrawString(strText, font, XBrushes.Black, _rect, XStringFormats.Center);

        }

        private void DrawBoxWithTextLeft(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, double borderWidth, string strText, string strText2, string strFontName, double fontSize, XFontStyle xFontStyle, int textalignment)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = width;
            _rect.Height = height;
            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            XFont font = new XFont(strFontName, fontSize, xFontStyle);
            XFont font2 = new XFont(strFontName, fontSize, XFontStyle.Regular);
            _objG.DrawRectangle(_pen, _rect);
            _objG.DrawString(strText, font, XBrushes.Black, new XRect(x + 5, y + 5, width, height), XStringFormats.TopLeft);
            _objG.DrawString(strText2, font2, XBrushes.Black, new XRect(x + textalignment, y + 5, width, height), XStringFormats.TopLeft);

        }

        private void DrawBoxWithTextList(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, int rows, int cols, double borderWidth, string strFontName, double fontSize, XFontStyle xFontStyle, string[,] _arrData, int[] _arrColsWidth)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = width;
            _rect.Height = (height + 8) * rows;

            XColor _xOuterBoxColor = new XColor();
            _xOuterBoxColor.R = 0;
            _xOuterBoxColor.G = 0;
            _xOuterBoxColor.B = 0;

            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            XFont font = new XFont(strFontName, fontSize, xFontStyle);
            XFont boldFont = new XFont(strFontName, fontSize, XFontStyle.Bold);
            _objG.DrawRectangle(_pen, _rect);

            System.Drawing.Rectangle _rectText = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rectText.X = x + 5;
            _rectText.Y = y + 5;
            _rectText.Width = width;
            _rectText.Height = height;

            for (int i = 0; i < rows; i++)
            {
                // Draw the text
                for (int j = 0; j < cols; j++)
                {
                    _rectText.Width = _arrColsWidth[j];
                    if (j == 0)
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), boldFont, XBrushes.Black, _rectText, XStringFormats.TopLeft);
                    }
                    else
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, _rectText, XStringFormats.TopLeft);
                    }
                    _rectText.X += _arrColsWidth[j];
                }
                _rectText.X = x + 5;
                _rectText.Y += height + 5;
            }

        }

        private void DrawTable(XGraphics _objG, int x, int y, int rows, int cols, int rowHeight, int[] _arrColsWidth, string[] _arrHeader, string[,] _arrData)
        {
            XColor _xcolor = new XColor();
            _xcolor.R = 0;
            _xcolor.G = 0;
            _xcolor.B = 0;
            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = _arrColsWidth[0];
            _rect.Height = rowHeight;
            XPen _pen = new XPen(_xcolor);
            _pen.Width = 0.5d;
            XFont font = new XFont("Verdana", 5, XFontStyle.Regular);

            for (int h = 0; h < cols; h++)
            {
                _rect.Width = _arrColsWidth[h];
                _objG.DrawRectangle(_pen, _rect);
                _objG.DrawString(_arrHeader[h].ToString(), font, XBrushes.Black,
          new XRect(_rect.X + 3, _rect.Y + 3, 10, 10),
          XStringFormats.TopLeft);
                _rect.X += _arrColsWidth[h];
            }

            _rect.Y += rowHeight;
            _rect.X = x;

            for (int i = 0; i < rows; i++)
            {
                // Draw the text
                for (int j = 0; j < cols; j++)
                {
                    _rect.Width = _arrColsWidth[j];

                    _objG.DrawRectangle(_pen, _rect);
                    _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black,
              new XRect(_rect.X + 3, _rect.Y + 3, 10, 10),
              XStringFormats.TopLeft);
                    _rect.X += _arrColsWidth[j];
                }
                _rect.Y += rowHeight;
                _rect.X = x;
            }
        }

        public void ClearFields()
        {
            _proposalId = "";
            _schedulewritingpagetitle = "Etiqa - Schedule Writing";// "Etiqa - Schedule Writing
            _certificatepagetitle = "Etiqa - Certificate Of Insurance";// "Etiqa - Certificate Of Insurance
            _taxinvoicepagetitle = "Etiqa - Tax";// "Etiqa - Tax

            #region Customer Profile
            _customerName = "";// "BRYAN YU CHEE SIANG
            _customerAddress1 = "";// "123, JALAN 222
            _customerAddress2 = "";// "SINGAPORE 604565
            #endregion

            #region Schedule Writing Variables
            _agency = "";// "001045
            _classOfPolicy = "";// "MOTOR PRIVATE CAR
            _policyNumber = "";// "DMAP105004354
            _account = "";// "001045
            _issuedOn = "";// CE.Global.General.GetUTCDateTime().Day.ToString("00") + "/" + CE.Global.General.GetUTCDateTime().Month.ToString("00") + "/" + CE.Global.General.GetUTCDateTime().Year.ToString("0000") + " in SINGAPORE
            _replacePolicyNumber = "";// "DMAP095006346
            _client = "";// "
            _acceptanceDate = "";// CE.Global.General.GetUTCDateTime().Day.ToString("00") + "/" + CE.Global.General.GetUTCDateTime().Month.ToString("00") + "/" + CE.Global.General.GetUTCDateTime().Year.ToString("0000")="";
            //_basicPremiumAmount = "";// "S$1,529.55
            //_lessNCDPercent = "";// "50.00%
            //_lessNCDAmount = "";// "S$764.78-
            //_ncdProtectionPremiumPercent = "";// "10%
            //_ncdProtectionPremiumAmount = "";// "S$76.48
            //_totalAnnualPermium = "";// "S$841.25
            //_premiumDue = "";// "S$841.25
            //_premiumGST = "";// "S$58.89
            //_totalDueInvoice = "";// "S$900.14
            //_totalDueSchedule = "";// "S$900.14
            _occupation = "";// "INDOOR - IT

            #endregion



            #region Tax Invoice Variables
            _gstRegNumber = "";// "M90363266Y

            _transDate = "";// CE.Global.General.GetUTCDateTime().ToShortDateString()="";

            _branchTerritory = "";// "SINGAPORE / Singapore
            _accountAgency = "";
            _cardType = "";

            _cardLastFourDigit = "";
            #endregion
        }

        private string GetFilePath()
        {
            string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("FileOutputPath").ToString();
            _filePath += "pdfoutput\\etiqa\\";
            CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
            string _todaydate = CE.Global.General.GetUTCDateTime().ToString("yyyyMMMdd");
            if (!_myIO.CheckDirectory(_filePath + _todaydate))
            {
                if (_myIO.CreateDirectory(_filePath, _todaydate))
                {
                    _filePath += _todaydate + "\\";
                }
            }
            else
            {
                _filePath += _todaydate + "\\";
            }

            return _filePath;
        }
    }
}